package exam.huawei.string;

import java.util.Arrays;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 运维日志排序
 * https://fcqian.blog.csdn.net/article/details/126003757
 */
public class Example14 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = Integer.parseInt(sc.nextLine());

        String[] logs = new String[n];
        for (int i = 0; i < n; i++) {
            logs[i] = sc.nextLine();
        }

        getResult(logs);
    }

    public static void getResult(String[] logs) {
        Arrays.sort(logs, (a, b) -> (int) (convet(a) - convet(b)));

        for (String log : logs) {
            System.out.println(log);
        }
    }

    /**
     * 将所有的时间转化为毫秒数再进行比对
     */
    public static long convet(String log) {
        String reg = "(\\d+):(\\d+):(\\d+).(\\d+)";

        Matcher matcher = Pattern.compile(reg).matcher(log);

        if (matcher.find()) {
            long H = Long.parseLong(matcher.group(1)) * 60 * 60 * 1000;
            long M = Long.parseLong(matcher.group(2)) * 60 * 1000;
            long S = Long.parseLong(matcher.group(3)) * 1000;
            long N = Long.parseLong(matcher.group(4));
            return H + M + S + N;
        } else {
            return 0;
        }
    }
}